package com.yanqu.road.server.cmd.strongholdwar.eliminate;

import com.yanqu.road.entity.activity.stronghold.CrossStrongholdEliminateUnion;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.logic.pb.CrossRankPb;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_CROSS_STRONGHOLD_UPLOAD_UNION_BASE, desc = "")
public class CrossUploadUnionBaseCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossUploadUnionBaseMsgReq req = StrongholdWarProto.CrossUploadUnionBaseMsgReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        List<StrongholdWarProto.UnionBaseDataMsg> unionBaseList = req.getUnionBaseList();
        List<CrossStrongholdEliminateUnion> eliminateUnions = new ArrayList<>();
        for (StrongholdWarProto.UnionBaseDataMsg msg : unionBaseList) {
            UnionBaseInfo unionBaseInfo = CrossRankPb.parseUnionBaseInfo(msg.getUnionInfo());
            CrossStrongholdEliminateUnion base = new CrossStrongholdEliminateUnion();
            base.setActivtyId(activityId);
            base.setServerId(unionBaseInfo.getServerId());
            base.setUnionBaseInfo(unionBaseInfo);
            base.setUnionUid(msg.getUnionUid());
            eliminateUnions.add(base);
        }
        CrossStrongholdMgr.uploadBase(activityId, groupId, serverId, eliminateUnions);
    }

    @Override
    public void sendData() {

    }
}
